<?php

require_once 'mysqli.class.php';

class DBconfigTest {
    private $config = array(
        'host'=>'localhost',
        'user'=>'root',
        'pass'=>'root',
        'table'=>''
    );
    
    public $DB;
    
    public function initalDB($newDBName){
        
        if($this->DB->checkDB_exist($newDBName)){
            //die("Database already existed, please change the name");
            die ("$newDBName already exist");
        }else{
            $TempCreateDb = "CREATE DATABASE $newDBName";
            $this->DB->query($TempCreateDb);
            $this->config['table']= $newDBName;
             
        }
    }
    
    public function registerAdmin($GiveName, $Surname, $Email, $PW){
        
        $emailUniqcheck = "SELECT `email` FROM `roster_users`.`users` WHERE `email` = '$Email'";
        $this->DB->query($emailUniqcheck);
        $result = $this->DB->get();
        if(count($result)==0){
            $TempSQLregistAdmin = "INSERT INTO `roster_users`.`users` (`user_id`, `gName`, `surname`, `email`, `pw`, `admin`, `rosterDBName`) VALUES (NULL, '$GiveName', '$Surname','$Email','$PW','1','')";
            $this->DB->query($TempSQLregistAdmin);
            echo 'Create successful<br>';
        }else{
            die("Email is already registed, please change another one");
        }
        
    }

        public function __construct() {
        $this->DB = new DB($this->config);

    }
    
}
?>
